package com.mes.controller.manu;

import com.yy.base.common.service.EntityService;
import com.yy.base.page.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("orderInfoController")
public class OrderInfoController {
	@Autowired
	private EntityService service;

	//获取生产工单信息
	@ResponseBody
	@RequestMapping(value="searchOrderInfo", method=RequestMethod.POST)
	public Message searchOrderInfo(HttpServletRequest request) {
		Message msg = new Message();
		try {
			String orgId = (String)request.getSession().getAttribute("orgId");
			String code = request.getParameter("code").toUpperCase();

			List<Map<String, Object>> data = getOrderInfo(code);
			if (data == null || data.isEmpty()) {
				msg.setErrorMessage("根据编码未找到对应的工单！");
			} else {
				if (orgId != null && !orgId.equals(data.get(0).get("AD_ORG_ID"))) {
					msg.setErrorMessage("此工单为" + data.get(0).get("ORGNAME") + "所有，不能在本车间执行！");
				} else {
					msg.setData("data", data);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			msg.setErrorMessage("查询异常：" + e.getMessage());
		}
		return msg;
	}

	private List<Map<String, Object>> getOrderInfo(String orderCode) {

		return null;
	}
}